package org.example.controller.defaultDir;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.model.common.PageResponseDto;
import org.example.model.common.ResponseResult;
import org.example.model.project.dtos.ProjectInfoDto;
import org.example.model.project.statement.ProjectTimeSpent;
import org.example.model.project.vos.AddProjectInfoVo;
import org.example.model.project.vos.SearchProjectInfoVo;
import org.example.controller.common.permission.PermissionControl;
import org.example.service.project.ProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目信息表现层
 */
@CrossOrigin
@RestController
@RequestMapping("/project-info")
@Api(value = "项目信息接口", tags = {"项目信息接口"})
@PermissionControl(Name = "项目管理", Order = 1)
public class ProjectInfoController {

    @Autowired
    private ProjectInfoService projectInfoService;

    /**
     * 添加一则项目信息记录
     */
    @PostMapping
    @ApiOperation("添加一则项目信息记录")
    @PermissionControl(Parent = "项目管理", Name = "添加", Order = 1)
    public ResponseResult<Boolean> InsertProjectInfo(@RequestBody AddProjectInfoVo addProjectInfoVo) {
        return projectInfoService.InsertProjectInfo(addProjectInfoVo);
    }

    /**
     * 根据id修改一则项目信息记录
     */
    @PutMapping
    @ApiOperation("根据id修改一则项目信息记录")
    @PermissionControl(Parent = "项目管理", Name = "修改", Order = 3)
    public ResponseResult<Boolean> UpdateProjectInfoById(@RequestBody AddProjectInfoVo addProjectInfoVo) {
        return projectInfoService.UpdateProjectInfoById(addProjectInfoVo);
    }

    /**
     * 根据id删除一则项目信息记录
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除一则项目信息记录")
    @PermissionControl(Parent = "项目管理", Name = "删除", Order = 2)
    public ResponseResult<Boolean> DeleteProjectInfoById(@PathVariable int id) {
        return projectInfoService.DeleteProjectInfoById(id);
    }

    /**
     * 根据条件分页查询项目信息
     */
    @GetMapping("/project-list")
    @ApiOperation("根据条件分页查询项目信息")
    @PermissionControl(Parent = "项目管理", Name = "查询", Order = 4)
    public ResponseResult<PageResponseDto<List<ProjectInfoDto>>> SelectProjectInfoListByConditions(SearchProjectInfoVo searchProjectInfoVo) {
        return projectInfoService.SelectProjectInfoListByConditions(searchProjectInfoVo);
    }

    /**
     * 获取除公司开发类别以外的项目总用时统计
     */
    @GetMapping("/project-time-spent")
    @ApiOperation("获取除公司开发类别以外的项目总用时统计")
    @PermissionControl(Parent = "项目管理", Name = "项目总用时统计", Order = 5)
    public ResponseResult<List<ProjectTimeSpent>> GetAllProjectExCompanyTimeSpent() {
        return projectInfoService.GetAllProjectExCompanyTimeSpent();
    }
}
